/****************************************************
	文件：UILevel.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/10/12 17:38:19
	功能：关卡 Wnd
*****************************************************/

using System;
using UnityEngine;
using HTUtility;
using HTFramework.UIKit;

namespace HTDemo01
{
    public class UILevel : WndBase
    {
        private LevelPanel mLevelPanel;
        private ReactiveProperty<int> Score;

        public override void OnAwake(params object[] paramLst)
        {
            base.OnAwake(paramLst);
            mLevelPanel = GetPanel<LevelPanel>();
            Score = new ReactiveProperty<int>(-1);
            mLevelPanel.Txt_TitleScore.text = "得分：";
            mLevelPanel.Txt_LevelNum.text = string.Format("第{0}关", LevelMgr.Instance.CurLevel);
            mLevelPanel.Txt_NextLevel.text = "下一关";
        }

        public override void OnShow(params object[] paramLst)
        {
            base.OnShow(paramLst);
            Score.Value = LevelMgr.Instance.Score.Value;
        }

        protected override void RegisterEvent()
        {
            base.RegisterEvent();
            Score.Subscribe(newScore =>
            {
                mLevelPanel.Txt_TitleScoreNum.text = newScore.ToString();
            });
            SubscribeEvent(HTUtility.EventType.LEVEL_SCORE_CHANGE, (newScore) =>
            {
                Score.Value = (int)newScore[0];
            });
            AddBtnClick(mLevelPanel.Btn_NextLevel, StartNextLevel);
        }


        private void StartNextLevel()
        {
            int nextLevel = Mathf.Min(LevelMgr.Instance.CurLevel + 1, 5);
            LevelMgr.Instance.StartLevel(nextLevel);
            UIMgr.Instance.CloseWnd(GConsts.LEVEL_PANEL, true);
        }
    }
}
